#include <bits/stdc++.h>

using namespace std;

int a[200005], n, ans;
bool color[200005];

void f(int x){
    if (x > n){
        bool first0 = true, first1 = true;
        int tmp = 0, it;
        for (int i = 1; i <= n; i++){
            if(!color[i]){
                if(first0) first0 = false;
                else{
                    for(it = i- 1;; it--) if(!color[it]) break;
                    tmp += a[i]==a[it]? a[i]: 0;
                }
            } else {
                if(first1) first1 = false;
                else{
                    for(it = i - 1;; it--) if(color[it]) break;
                    tmp += a[i]==a[it]? a[i]: 0;
                }
            }
        }
        ans = max(ans, tmp);
        return ;
    }
    color[x] = 0; f(x + 1);
    color[x] = 1; f(x + 1);
    return ;
}

void solve() {
    cin >> n; ans = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    f(1);
    cout << ans << endl;
    return ;
}

int main () {
    freopen("color.in","r",stdin);
    freopen("color.out", "w", stdout);
    int t; cin >> t;
    while(t--) solve();
    return 0;
}
